<?php

namespace app\supplier\controller\supplier;

use app\Request;
use app\supplier\controller\Controller;
use app\supplier\controller\store\Order;
use app\supplier\model\supplier\InvoiceOrderModel;

/**
 * 供应商
 */
class InvoiceOrder extends Controller
{
    public function editBlack(Request $request)
    {
        $params = $request->param();
        $one = InvoiceOrderModel::one($params, ['order', 'invoice']);
        return $this->renderSuccess('', $one);
    }

    public function edit(Request $request)
    {
        $params = $request->param();
        $one = InvoiceOrderModel::listAll(['order_id' => $params['id']], ['invoice', 'order']);
        return $this->renderSuccess('', $one[0]);
    }

    public function update(Request $request)
    {
        $params = $request->param();
        $one = InvoiceOrderModel::one(['id' => $params['id']], ['order'])->toArray();
        $one['status'] = 1;
        InvoiceOrderModel::update($one);
        $om = new \app\supplier\model\order\Order();
        $order = $om->where(['order_id' => $one['order']['order_id']])->find();
        $order['is_invoice'] = 2;
        $order->save();
        return $this->renderSuccess('操作成功');
    }
}
